﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lenovo.CFI.Common
{
    public class Idea
    {
        public Idea()
        {
        }

        public Idea(int id)
        {
            this.id = id;
        }

        #region fields

        private int id;
        private int topicID;
        private int no;
        private string title;
        private string type;
        private CodeList relatedType;
        private CodeList keywords;
        private CodeList freewords;
        private string backgroud;
        private string description;
        private string values;
        private Guid? pptFileID;
        private Guid? pic1FileID;
        private Guid? pic2FileID;
        private Guid? pic3FileID;
        private string owner;
        private int teamID;
        private string teamManager;
        private string teamVP;
        private IdeaStatus status;
        private DateTime submitTime;
        private string approver;
        private string approverComment;
        private string dcComment;
        private bool? dcAttendMeeting;
        private int secretLevel;
        private bool canSearch;

        private int? finalReviewTopicID;
        private int? finalReviewID;
        private int? finalAward;
        private string finalType;
        private bool? finalIP;
        private string finalAction;
        private string finalActionBU;
        private ExecutionStatus finalActionStatus;
        private ExecutionStatus finalIPStatus;

        #endregion

        #region properities

        public int ID
        {
            get { return id; }
            set { id = value; }
        }

        /// <summary>
        /// 提交时对应的Topic
        /// </summary>
        public int TopicID
        {
            get { return topicID; }
            set { topicID = value; }
        }

        /// <summary>
        /// 编号 -- 时间表确定后按顺序生成
        /// </summary>
        public int No
        {
            get { return no; }
            set { no = value; }
        }

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        /// <summary>
        /// 申请时的类型
        /// </summary>
        public string Type
        {
            get { return type; }
            set { type = value; }
        }

        /// <summary>
        /// 相关技术方向
        /// </summary>
        public CodeList RelatedType
        {
            get { return relatedType; }
            set { relatedType = value; }
        }

        public string RelatedTypeText
        {
            get 
            {
                if (this.relatedType == null)
                    return null;
                else
                    return relatedType.Text; 
            }
        }

        /// <summary>
        /// 关键字（最多3个）（选择）
        /// </summary>
        public CodeList Keywords
        {
            get { return keywords; }
            set { keywords = value; }
        }

        public string KeywordsText
        {
            get
            {
                if (this.keywords == null)
                    return null;
                else
                    return keywords.Text;
            }
        }

        /// <summary>
        /// 关键字（不限）（输入）
        /// </summary>
        public CodeList Freewords
        {
            get { return freewords; }
            set { freewords = value; }
        }

        public string FreewordsText
        {
            get
            {
                if (this.freewords == null)
                    return null;
                else
                    return freewords.Text;
            }
        }

        public string Backgroud
        {
            get { return backgroud; }
            set { backgroud = value; }
        }

        public string Description
        {
            get { return description; }
            set { description = value; }
        }

        public string Values
        {
            get { return values; }
            set { values = value; }
        }

        public Guid? PptFileID
        {
            get { return pptFileID; }
            set { pptFileID = value; }
        }

        public Guid? Pic1FileID
        {
            get { return pic1FileID; }
            set { pic1FileID = value; }
        }

        public Guid? Pic2FileID
        {
            get { return pic2FileID; }
            set { pic2FileID = value; }
        }

        public Guid? Pic3FileID
        {
            get { return pic3FileID; }
            set { pic3FileID = value; }
        }

        public string Owner
        {
            get { return owner; }
            set { owner = value; }
        }

        /// <summary>
        /// 申请时Owner所在的Team
        /// </summary>
        public int TeamID
        {
            get { return teamID; }
            set { teamID = value; }
        }

        /// <summary>
        /// 申请时Owner所在的Team的Manager
        /// </summary>
        public string TeamManager
        {
            get { return teamManager; }
            set { teamManager = value; }
        }

        /// <summary>
        /// 申请时Owner所在的Team的VP
        /// </summary>
        public string TeamVP
        {
            get { return teamVP; }
            set { teamVP = value; }
        }

        public IdeaStatus Status
        {
            get { return status; }
            set { status = value; }
        }

        public DateTime SubmitTime
        {
            get { return submitTime; }
            set { submitTime = value; }
        }

        /// <summary>
        /// 申请审批人，无表示无需要审批
        /// </summary>
        public string Approver
        {
            get { return approver; }
            set { approver = value; }
        }

        /// <summary>
        /// 申请审批人意见
        /// </summary>
        public string ApproverComment
        {
            get { return approverComment; }
            set { approverComment = value; }
        }

        /// <summary>
        /// DC意见
        /// </summary>
        public string DcComment
        {
            get { return dcComment; }
            set { dcComment = value; }
        }

        /// <summary>
        /// DC是否建议参加评审会议
        /// </summary>
        public bool? DcAttendMeeting
        {
            get { return dcAttendMeeting; }
            set { dcAttendMeeting = value; }
        }

        /// <summary>
        /// 保密级别，默认1
        /// </summary>
        public int SecretLevel
        {
            get { return secretLevel; }
            set { secretLevel = value; }
        }

        /// <summary>
        /// 是否可以被检索 -- Idea必须在Topic评审完成后才能被检索
        /// </summary>
        public bool CanSearch
        {
            get { return canSearch; }
            set { canSearch = value; }
        }



        public int? FinalReviewTopicID
        {
            get { return finalReviewTopicID; }
            set { finalReviewTopicID = value; }
        }

        public int? FinalReviewID
        {
            get { return finalReviewID; }
            set { finalReviewID = value; }
        }

        public int? FinalAward
        {
            get { return finalAward; }
            set { finalAward = value; }
        }

        public string FinalType
        {
            get { return finalType; }
            set { finalType = value; }
        }

        public bool? FinalIP
        {
            get { return finalIP; }
            set { finalIP = value; }
        }

        public string FinalAction
        {
            get { return finalAction; }
            set { finalAction = value; }
        }

        public string FinalActionBU
        {
            get { return finalActionBU; }
            set { finalActionBU = value; }
        }

        public ExecutionStatus FinalActionStatus
        {
            get { return finalActionStatus; }
            set { finalActionStatus = value; }
        }

        public ExecutionStatus FinalIPStatus
        {
            get { return finalIPStatus; }
            set { finalIPStatus = value; }
        }



        public string StatusText
        {
            get 
            {
                string text = "";
                switch (this.status)
                {
                    case IdeaStatus.Draft:
                        text = "Draft";
                        break;
                    case IdeaStatus.Approving:
                        text = "Approving";
                        break;
                    case IdeaStatus.Reject:
                        text = "Reject";
                        break;
                    case IdeaStatus.Agree:
                        text = "Agree";
                        break;
                    case IdeaStatus.Submitted:
                        text = "Submitted";
                        break;
                    case IdeaStatus.ReviewPreparing:
                        text = "Reviewing";
                        break;
                    case IdeaStatus.Reviewing:
                        text = "Reviewing";
                        break;
                    case IdeaStatus.ReviewClosed:
                        text = "Reviewing";
                        break;
                    case IdeaStatus.ReviewCanceled:
                        text = "NotReview";
                        break;
                    case IdeaStatus.Suggestion:
                        text = "Suggestion";
                        break;
                    case IdeaStatus.Execution:
                        text = "Execution";
                        break;
                    case IdeaStatus.Closed:
                        text = "Closed";
                        break;
                }

                return text;
            }
        }

        public string FinalActionStatusText
        {
            get
            {
                return GetExecutionStatus(this.finalActionStatus);
            }
        }

        public string FinalIPStatusText
        {
            get
            {
                return GetExecutionStatus(this.finalIPStatus);
            }
        }


        public static string GetExecutionStatus(ExecutionStatus? status)
        {
            if (status == null) return "";

            string text = "";


            switch (status.Value)
            {
                case ExecutionStatus.Preparing:
                    text = "Preparing";
                    break;
                case ExecutionStatus.OnGoing:
                    text = "OnGoing";
                    break;
                case ExecutionStatus.Finished:
                    text = "Finished";
                    break;
                case ExecutionStatus.Canceled:
                    text = "Canceled";
                    break;

            }

            return text;
        }

        #endregion



        private IdeaReview finalReview;

        public IdeaReview FinalReview
        {
            get { return finalReview; }
            set { finalReview = value; }
        }
    }

    public enum IdeaStatus
    {
        /// <summary>
        /// 草稿 -- 可以取消
        /// </summary>
        Draft = 11,
        /// <summary>
        /// 提交/审批中
        /// </summary>
        Approving = 12,
        /// <summary>
        /// 审批拒绝
        /// </summary>
        Reject = 13,
        /// <summary>
        /// 审批通过
        /// </summary>
        Agree = 14,
        /// <summary>
        /// 直接提交
        /// </summary>
        Submitted = 15,

        /// <summary>
        /// 评审准备
        /// </summary>
        ReviewPreparing = 21,
        /// <summary>
        /// 评审中
        /// </summary>
        Reviewing = 22,
        /// <summary>
        /// 评审结束
        /// </summary>
        ReviewClosed = 23,
        /// <summary>
        /// 不参与评审
        /// </summary>
        ReviewCanceled = 24,

        /// <summary>
        /// 建议
        /// </summary>
        Suggestion = 31,

        /// <summary>
        /// 执行
        /// </summary>
        Execution = 41,

        /// <summary>
        /// 结束
        /// </summary>
        Closed = 51
    }

    public enum ExecutionStatus
    {
        None = 0,
        Preparing = 1,
        OnGoing = 2,
        Finished = 3,
        Canceled = 4,
    }

    public enum SuggestionStatus
    {
        None = 0,
        OnGoing = 1,
        Reject = 2,
        Finished = 3
    }
}
